/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef ITEMPOSITIONCALCULATOR_H
#define ITEMPOSITIONCALCULATOR_H

#include <QObject>
#include <QMap>

class ItemPositionCalculator
{
public:
    using ItemPostion = std::tuple<int, int, int>;
    using ItemPostionInOnePage = std::tuple<int, int>;
    using ItemIdsInPageGrid = QList<QList<int>>;
    using ItemIdsInAllPageGrid = QMap<int, QList<QList<int>>>;

    explicit ItemPositionCalculator();

    ItemPostion calculationPosition(int desktopPageRow, int desktopPageColumn,
                                    ItemIdsInAllPageGrid &itemIdsInAllPageGrid,
                                    int rowSpan, int columnSpan);

private:
    ItemIdsInPageGrid createGridItemIds(int rowCount, int colCount);
    virtual ItemPostionInOnePage doCalculate(const ItemIdsInPageGrid &itemIdsInPageGrid,
                                             int desktopPageRow, int dekstopPageColumn,
                                             int rowSpan = 1, int colSpan = 1) = 0;
};

class AppWidgetPositionCalculator : public ItemPositionCalculator
{
public:
    explicit AppWidgetPositionCalculator();

private:
    ItemPostionInOnePage doCalculate(const ItemIdsInPageGrid &itemIdsInPageGrid,
                                     int desktopPageRow, int dekstopPageColumn,
                                     int rowSpan = 1, int columnSpan = 1) override;
};

class AppItemPositionCalculator : public ItemPositionCalculator
{
public:
    explicit AppItemPositionCalculator() {}

private:
    ItemPostionInOnePage doCalculate(const ItemIdsInPageGrid &itemIdsInPageGrid,
                                     int desktopPageRow, int dekstopPageColumn,
                                     int rowSpan = 1, int columnSpan = 1) override;
};

#endif // ITEMPOSITIONCALCULATOR_H
